package com.xxx.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.xxx.util.ThreadLocalUntil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MPMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", LocalDateTime.now());
//        System.out.println(BaseContext.getCurrentId());
//        Subject subject = SecurityUtils.getSubject();
//        Employee employee = (Employee) subject.getPrincipal();


    }

    @Override
    public void updateFill(MetaObject metaObject) {

//        Subject subject = SecurityUtils.getSubject();
//        Employee employee = (Employee) subject.getPrincipal();
        Long currentId = ThreadLocalUntil.getCurrentId();

        metaObject.setValue("updateTime", LocalDateTime.now());

        metaObject.setValue("updateUser", currentId);
    }
}
